package com.itheima.d4_collection_list;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;

public class ListAttention {
    public static void main(String[] args) {
        //删除PHO
        LinkedList<String> list = new LinkedList<>();
        list.add("Java");
        list.add("黑马");
        list.add("Java");
        list.add("Mybatis");
        list.add("PHO");
        list.add("PHO");
        System.out.println(list);
        //for each删除
        for (String ele : list) {
            if ("PHO".equals(ele)){
                list.remove(ele);
            }
        }
        System.out.println(list);


        // 迭代器遍历且删除PHO
       /* Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()){
            String ele = iterator.next();
            if("PHO".equals(ele)){
                //list.remove(ele);  //这样会漏删，我们用itreator.remove
                iterator.remove();
            }
        }
        System.out.println(list);*/
    }
}
